class Solution(object):
    def equalSubstring(self, s, t, maxCost):
        n = len(s)
        diff = [abs(ord(s[i]) - ord(t[i])) for i in range(n)]
        maxlen = 0
        now = 0
        left = 0
        right = 0
        while right < n:
            now += diff[right]
            while now > maxCost:
                now -= diff[left]
                left += 1
            maxlen = max(maxlen, right - left + 1)
            right += 1
        return maxlen